package org.iori.luodan.util;

import java.io.UnsupportedEncodingException;

/**
 * 字符串处理工具类
 * @author wang_zhibin
 * 
 */
public class StringUtil {

	public static String changeEncode(String str,String fromEncoding, String toEncoding) {
		try {
			if (str == null) return null;
			
			return new String(str.getBytes(fromEncoding), toEncoding);
		} catch (UnsupportedEncodingException e) {
			return str;
		}
	}
	
	public static boolean isNull(String str){
		if(str == null || str.equalsIgnoreCase("null") || str.trim().equals("")) return true;
		return false;
	}
	
	public static String displayAdjustment(String str , int length) {
	
			if (isNull(str)) return "";
			if( str.length()<= length) return str;
			int l = str.length();
			int m = l%length;
			int linenum = (str.length()-m)/length;
			StringBuffer sb = new StringBuffer();
		    for(int i=0 ; i < linenum ;i++){
		    	int start = i * length ;
		    	int end = (i+1)*length ;
		    	
		    	sb.append(str.substring(start, end) + "<br/>");
		    	if(m>0&&(i==(linenum-1))) sb.append(str.substring(end));
		    }
		    
			return sb.toString();
	 
	}

	public static String numToTime(String dateNum) {
		String timeStr="";
		String year="";
		String month="";
		String day="";
		String hour="";
		String min="";
		String sec="";
		
		year=dateNum.substring(0,4);
		month=dateNum.substring(4,6);
		day=dateNum.substring(6,8);
		hour=dateNum.substring(8,10);
		min=dateNum.substring(10,12);
		sec=dateNum.substring(12,14);
		timeStr=year+"/"+month+"/"+day+"<br />"+"&nbsp;&nbsp;"+hour+":"+min+":"+sec;
		return timeStr;
	}
	
	public static void main(String[] args){
		
		String s = numToTime("2010101918205567");
	    System.out.println(s);
	}
}
